<template>
  <el-dialog :title="title" :visible="visible" @close="visible=false">
    <el-form
      ref="form"
      :model="entityData"
      :rules="rules"
      label-width="80px"
      label-position="right"
      style="width:90%;margin:0px auto;"
    >
      <!--表单区域 -->
      <el-form-item label="消息标题" prop="title">
        <el-input v-model="entityData.title" :readonly="readonly" />
      </el-form-item>
      <el-form-item label="消息内容" prop="content">
        <el-input
          type="textarea"
          :rows="5"
          :readonly="readonly"
          style="border:1px solid #DCDFE6"
          v-html="entityData.content"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button v-show="saveButtonVisible" type="primary" @click="save">保存</el-button>
      <el-button type="primary" @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { detailMixin } from '@/mixin/detailMixin'
const MODULE_CODE = 'support'
const ENTITY_TYPE = 'message'
export default {
  name: ENTITY_TYPE + '-detail',
  mixins: [detailMixin],
  data() {
    return {
      entityType: ENTITY_TYPE,
      moduleCode: MODULE_CODE,
      // eslint-disable-next-line no-eval
      api: eval('this.$api.' + MODULE_CODE + '.' + ENTITY_TYPE),
      pageCode: MODULE_CODE + ':' + ENTITY_TYPE + ':',
      entityData: {

      },
      rules: {

      },
      // 更新过已读状态
      changeSatusFlag: false
    }
  },
  methods: {
    afterView() {
      // 默认设置为false，否则多次打开的情况下，会保留上次状态
      // 而上次状态可能为true，导致查看已读的消息，关闭窗口仍然会刷新父页面
      this.changeSatusFlag = false
      // 查看时如状态为未读，设置已读
      if (this.entityData.readFlag === this.constant.YES_OR_NO.NO) {
        this.api.read(this.entityData.id).then(res => {
          this.entityData = res.data
          this.changeSatusFlag = true
          // 未读消息减1
          this.$store.dispatch('app/decreaseUnreadMessageCount')
        })
      }
    },
    // 关闭
    close() {
      if (this.changeSatusFlag) {
        this.$emit('ok')
      }
      this.visible = false
    }
  }

}
</script>

<style lang="scss">
</style>
